﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    public class ISSUEGREIGEReport : BaseReport
    {
        string strCompany = "HLT";
        string strExcelFile = "";
        string sheetName = "";
        string Standard = "ISSUEGREIGE";
        string filePath = @"C:\intex.w\Report\HLT\HLTPlanningReport.xls";
        public ISSUEGREIGEReport()
            : base()
        {
        }
        public ISSUEGREIGEReport(Dictionary<string, object> dicParamater)
            : base(dicParamater)
        {
            strCompany = dicParamater["Company"].ToString().Trim();
            strExcelFile = dicParamater["ExcelFile"].ToString().Trim();
            strExcelFile = @"HLT\HLTPlanningReport.xls"; 
            #region Excel  columns
                    columns.Add("ARTICLE");
                    columns.Add("BATCHNO");
                    columns.Add("MTR");
                    columns.Add("WMTR");
                    columns.Add("WORDERNO");
                    columns.Add("WFACTORY");
                    columns.Add("FORDERNO");
                    columns.Add("FFACTORY");
                    columns.Add("COLORDES");
                    columns.Add("COMPOSITION");
                    columns.Add("WAFBRTL");
                    columns.Add("JS");
                    columns.Add("WS");
                    columns.Add("RATE");
                    columns.Add("PRICE");
                    columns.Add("BATCHQTY");
                    columns.Add("BATCHMTR");
                    columns.Add("FINISHQTY");
                    columns.Add("FINISHMTR");
                    columns.Add("UNCHECKEDQTY");
                    columns.Add("UNCHECKEDMTR");
                    columns.Add("CHECKEDQTY");
                    columns.Add("CHECKEDMTR");
                    columns.Add("TOTALQTY");
                    columns.Add("TOTALMTR");            
                    columns.Add("REMARK");
            #endregion
               
        }
        public void FillInExcelData(ArrayList columns, DataSet setSoruce, int xStart = 2, int yStart = 1)
        {
            try
            {
                int x = xStart, y = yStart;
                DataTable dtSoruce = setSoruce.Tables["ISSUEGREIGE"];
                foreach (DataRow dataRow in dtSoruce.Rows)
                {
                    y = yStart;
                    foreach (string column in columns)
                    {
                        exAgent.SetCellValue(x, y, dataRow[column].ToString());
                        y++;
                    }
                    x++;
                } 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
      
        public override void WriteExcelReport(string fileType)
        {
            string filename = "";
            string sheetName = "";
            string Standard = "ISSUEGREIGE";
            strExcelFile = @"HLT\HLTPlanningReport.xls";
            string filePath = @"C:\intex.w\Report\" + strExcelFile;
            exAgent.Open(filePath);
            exAgent.Company = strCompany;
            exAgent.strExcelFile = strExcelFile;
            string filedate = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
            filename = @"Planning\后整理\发坯计划报表" + filedate + ".xls";
            sheetName = DateTime.Now.ToShortTimeString().Replace(@":", ""); 
            exAgent.CreateNewSheet(filename, Standard, sheetName);
            FillInExcelData(columns, dsSource, 3, 1);
            base.WriteExcelReport(fileType);
        }
    }
}
